package me.leiusual.sharing.ui.store.adapter

import android.view.View
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.extensions.LayoutContainer
import kotlinx.android.synthetic.main.view_holder_store_category.*
import me.leiusual.sharing.api.model.StoreCategories

/**
 * author: leiusual
 * create on: 2019-07-26
 * description:
 */
class StoreCategoryViewHolder(
    override val containerView: View,
    private val listener: Listener
) : RecyclerView.ViewHolder(containerView), LayoutContainer, View.OnClickListener {

  private lateinit var category: StoreCategories.Response.Category.Item

  init {
    containerView.setOnClickListener(this)
  }

  fun bind(category: StoreCategories.Response.Category.Item, selected: Boolean) {
    this.category = category

    text_view.text = category.name

    text_view.isSelected = selected
  }

  override fun onClick(v: View?) {
    listener.onCategoryClicked(category)
  }

  interface Listener {

    fun onCategoryClicked(category: StoreCategories.Response.Category.Item)
  }
}